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;
67 // ----------------------------------------------------------------------------
69 void manualViewBaseContour::Save(FILE *pFile)
71 fprintf(pFile,"TypeView %d\n", GetType() );
74 // ----------------------------------------------------------------------------
75 void manualViewBaseContour::Open(FILE *pFile)
79 // ----------------------------------------------------------------------------
80 void manualViewBaseContour :: AddCompleteContourActor( bool ifControlPoints )
82 _viewControlPoints = ifControlPoints;
83 /*vtkRenderer * theRenderer = */ _wxvtkbaseview->GetRenderer(); // JPRx ??
88 //Adding each control point
94 // ---------------------------------------------------------------------------
96 void manualViewBaseContour :: RemoveCompleteContourActor()
98 /*vtkRenderer * theRenderer =*/ _wxvtkbaseview->GetRenderer(); // JPRx ??
103 //Removing each point
104 RemoveControlPoints();
108 // ---------------------------------------------------------------------------
109 manualViewBaseContour * manualViewBaseContour :: Clone( )//virtual
111 manualViewBaseContour * clone = new manualViewBaseContour();
112 CopyAttributesTo(clone);
117 // ---------------------------------------------------------------------------
119 void manualViewBaseContour::CopyAttributesTo( manualViewBaseContour * cloneObject)
122 //XXXX::CopyAttributesTo(cloneObject);
124 cloneObject-> SetWxVtkBaseView( this->_wxvtkbaseview );
125 cloneObject-> SetSelected( this->GetSelected() );
126 cloneObject-> SetPosibleSelected( this->GetPosibleSelected() );
127 cloneObject-> SetIfViewControlPoints( this->GetIfViewControlPoints() );
128 cloneObject-> SetRange( this->GetRange() );
129 cloneObject-> SetZ( this->GetZ() );
130 cloneObject-> SetSpacing( _spc );
131 cloneObject-> SetColorNormalContour( _coulorNormal_r, _coulorNormal_g, _coulorNormal_b );
132 cloneObject-> SetColorEditContour( _coulorEdit_r, _coulorEdit_g, _coulorEdit_b );
133 cloneObject-> SetColorSelectContour( _coulorSelection_r, _coulorSelection_g, _coulorSelection_b );
135 int i, size = _lstViewPoints.size();
136 for ( i=0; i<size; i++ )
138 cloneObject->AddPoint( );
142 // ----------------------------------------------------------------------------
143 void manualViewBaseContour :: AddSplineActor()
145 vtkRenderer * theRenderer = _wxvtkbaseview->GetRenderer();
146 if (_contourVtkActor!=NULL)
147 theRenderer->AddActor( _contourVtkActor );
149 // ----------------------------------------------------------------------------
150 void manualViewBaseContour :: RemoveSplineActor() // virtual
152 vtkRenderer * theRenderer = _wxvtkbaseview->GetRenderer();
153 if (_contourVtkActor!=NULL)
154 theRenderer->RemoveActor( _contourVtkActor );
156 // ----------------------------------------------------------------------------
157 void manualViewBaseContour :: RemoveControlPoints()
159 if (_wxvtkbaseview!=NULL){
160 vtkRenderer * theRenderer = _wxvtkbaseview->GetRenderer();
161 int i,size=_lstViewPoints.size();
162 for (i=0;i<size; i++)
164 vtkActor * pointActor = _lstViewPoints[i]->GetVtkActor();
165 theRenderer->RemoveActor( pointActor );
168 SetIfViewControlPoints( false );
170 // ----------------------------------------------------------------------------
171 void manualViewBaseContour::AddControlPoints()
173 vtkRenderer * theRenderer = _wxvtkbaseview->GetRenderer();
174 SetIfViewControlPoints( true );
175 if( _viewControlPoints )
177 int i,size=_lstViewPoints.size();
178 for (i=0;i<size; i++)
180 vtkActor * pointActor = _lstViewPoints[i]->GetVtkActor();
181 theRenderer->AddActor( pointActor );
185 // ----------------------------------------------------------------------------
186 void manualViewBaseContour::AddTextActor()
188 _wxvtkbaseview->GetRenderer()->AddActor2D( _textActor );
190 // ----------------------------------------------------------------------------
191 void manualViewBaseContour::RemoveTextActor()
193 _wxvtkbaseview->GetRenderer()->RemoveActor2D( _textActor );
195 // ----------------------------------------------------------------------------
196 void manualViewBaseContour::DeleteVtkObjects()
198 if ( _contourVtkActor != NULL ) { _contourVtkActor -> Delete(); }
199 if ( _bboxMapper != NULL ) { _bboxMapper -> Delete(); }
200 if ( _pts != NULL ) { _pts -> Delete(); }
201 if ( _pd != NULL ) { _pd -> Delete(); }
202 _contourVtkActor = NULL;
209 // ----------------------------------------------------------------------------
210 void manualViewBaseContour::SetWidthLine(double width)
213 this->UpdateColorActor();
215 // for the control points
216 int id, size = _lstViewPoints.size();
217 for( id=0; id<size; id++)
219 this->_lstViewPoints[id]->SetWidthLine(_widthline);
224 // ----------------------------------------------------------------------------
225 double manualViewBaseContour::GetWidthLine()
230 // ----------------------------------------------------------------------------
231 void manualViewBaseContour::ConstructVTKObjects()
233 //JSTG 29-02-08 -----------------------------------------------
234 //int i , nps = _sizePointsContour;
236 int nps = _manContModel->GetNumberOfPointsSpline();
237 //-------------------------------------------------------------
239 _pts = vtkPoints::New();
240 _pts->SetNumberOfPoints(nps);
242 for (i=0 ; i<nps ; i++){
243 _pts->SetPoint(i, 0 , 0 , 0 );
245 // This is for the boundaring inicialisation
248 _pts->SetPoint(0, 0 , 0 , -1000 );
249 _pts->SetPoint(1, 0 , 0 , 1000 );
250 // _pts->SetPoint(0, -1000 , -1000 , -1000 );
251 // _pts->SetPoint(1, 1000 , 1000 , 1000 );
254 vtkCellArray *lines = vtkCellArray::New();
255 lines->InsertNextCell( nps /* +1 */ );
256 for ( i=0 ; i<nps+1 ; i++ ){
257 lines->InsertCellPoint(i % nps );
260 _pd = vtkPolyData::New();
261 _pd->SetPoints( _pts );
262 _pd->SetLines( lines );
263 lines->Delete(); //do not delete lines ??
265 _contourVtkActor = vtkActor::New();
266 _bboxMapper = vtkPolyDataMapper::New();
267 _bboxMapper->ScalarVisibilityOff( );
269 _bboxMapper->SetInput(_pd);
270 _bboxMapper->ImmediateModeRenderingOn();
271 _contourVtkActor->SetMapper(_bboxMapper);
272 _contourVtkActor->GetProperty()->BackfaceCullingOff();
276 _pd->ComputeBounds();
279 _textActor = vtkTextActor::New();
280 // _textActor->SetDisplayPosition(200, 200);
281 _textActor->SetInput("00");
282 // Set coordinates to match the old vtkScaledTextActor default value
283 // _textActor->GetPosition2Coordinate()->SetCoordinateSystemToNormalizedViewport();
284 // _textActor->GetPosition2Coordinate()->SetValue( 0.2 , 0.2 );
285 _textActor->GetPositionCoordinate()->SetCoordinateSystemToWorld ();
286 // _textActor->GetPositionCoordinate()->SetValue( 0.8 , 0.8 );
288 vtkTextProperty *tprop = _textActor->GetTextProperty();
289 tprop->SetFontSize(14);
290 tprop->SetFontFamilyToArial();
291 tprop->SetColor(0, 0, 1);
293 // ----------------------------------------------------------------------------
294 void manualViewBaseContour::CreateNewContour()
296 ConstructVTKObjects();
298 _wxvtkbaseview->GetRenderer()->AddActor( _contourVtkActor );
299 _wxvtkbaseview->GetRenderer()->AddActor2D(_textActor);*/
300 AddCompleteContourActor();
302 // ----------------------------------------------------------------------------
303 void manualViewBaseContour::UpdateViewPoint(int id) // virtual
305 manualPoint *mp = _manContModel->GetManualPoint(id);
308 double XX=mp->GetX(),YY=mp->GetY(),ZZ=mp->GetZ();
309 // wxVtk2DBaseView *wxvtk2Dbasevie = (wxVtk2DBaseView*)this->GetWxVtkBaseView();
310 // wxvtk2Dbasevie->TransformCoordinate_spacing_ModelToView(XX,YY,ZZ);
312 _lstViewPoints[id]->SetPositionXY( XX , YY ,_range, ZZ );
315 // ----------------------------------------------------------------------------
316 void manualViewBaseContour::UpdateViewPoints()
318 int id, size = _lstViewPoints.size();
319 for( id=0; id<size; id++)
321 UpdateViewPoint( id );
325 // ----------------------------------------------------------------------------
326 void manualViewBaseContour::AddPoint()
328 manualViewPoint *mvp = new manualViewPoint( this->GetWxVtkBaseView() );
331 // ----------------------------------------------------------------------------
332 void manualViewBaseContour::AddPoint( manualViewPoint * manualViewPoint )
334 _lstViewPoints.push_back( manualViewPoint );
337 manualViewPoint->SetSpacing(_spc);
339 vtkActor *actor = manualViewPoint->CreateVtkPointActor();
340 _wxvtkbaseview->GetRenderer()->AddActor( actor );
343 // ----------------------------------------------------------------------------
344 void manualViewBaseContour::InsertPoint(int id)
346 manualViewPoint *mvp = new manualViewPoint( this->GetWxVtkBaseView() );
349 mvp->SetSpacing(_spc);
351 std::vector<manualViewPoint*>::iterator itNum = _lstViewPoints.begin() + id;
352 _lstViewPoints.insert(itNum,mvp);
353 _wxvtkbaseview->GetRenderer()->AddActor( mvp->CreateVtkPointActor() );
355 // ----------------------------------------------------------------------------
356 void manualViewBaseContour::DeleteContour()
358 RemoveCompleteContourActor();
359 /*if (_contourVtkActor!=NULL){
360 _wxvtkbaseview->GetRenderer()->RemoveActor( _contourVtkActor );
363 int i,size=_lstViewPoints.size();
364 for (i=0;i<size;i++){
365 manualViewBaseContour::DeletePoint(0);
369 // ----------------------------------------------------------------------------
370 void manualViewBaseContour::DeletePoint(int id) // virtual
372 int size=_lstViewPoints.size();
373 if ( (id>=0) && (id<size) ){
374 manualViewPoint *mvp =_lstViewPoints[id];
376 // _handlePicker->DeletePickList(mvp->GetVtkActor());
377 _wxvtkbaseview->GetRenderer()->RemoveActor( mvp->GetVtkActor() );
378 std::vector<manualViewPoint*>::iterator itNum = _lstViewPoints.begin() + id;
379 _lstViewPoints.erase(itNum);
384 // ----------------------------------------------------------------------------
385 void manualViewBaseContour::DeletePoint(int x, int y, int z)
387 int id=GetIdPoint(x,y,z);
392 // ----------------------------------------------------------------------------
393 void manualViewBaseContour::SetSelected(bool selected)
397 // ----------------------------------------------------------------------------
398 void manualViewBaseContour::SetPosibleSelected(bool posibleSelected)
400 _posibleSelected=posibleSelected;
402 // ----------------------------------------------------------------------------
403 bool manualViewBaseContour::GetEditable()
407 // ----------------------------------------------------------------------------
408 void manualViewBaseContour::SetEditable( bool * condition )
410 _editable = condition;
412 // ----------------------------------------------------------------------------
413 bool manualViewBaseContour::GetSelected()
417 // ----------------------------------------------------------------------------
418 bool manualViewBaseContour::GetPosibleSelected()
420 return _posibleSelected;
422 // ----------------------------------------------------------------------------
423 void manualViewBaseContour::DeleteSelectedPoints()
425 int i,size=_lstViewPoints.size();
426 for (i=size-1;i>=0;i--){
427 if (_lstViewPoints[i]->GetSelected()==true){
433 // ----------------------------------------------------------------------------
434 void manualViewBaseContour::SelectPoint(int i, bool select)
436 _lstViewPoints[i]->SetSelected(select);
438 // ----------------------------------------------------------------------------
439 void manualViewBaseContour::SelectLstPoints()
443 // ----------------------------------------------------------------------------
444 void manualViewBaseContour::SelectAllPoints(bool select)
446 int i,size=_lstViewPoints.size();
447 for (i=0;i<size;i++){
448 SelectPoint(i,select);
451 //-----------------------------------------------------------------------------
452 void manualViewBaseContour:: SetIfViewControlPoints(bool ifShow)
454 _viewControlPoints = ifShow;
456 // ----------------------------------------------------------------------------
457 bool manualViewBaseContour:: GetIfViewControlPoints()
459 return _viewControlPoints;
462 // ----------------------------------------------------------------------------
463 void manualViewBaseContour::SetPointPosibleSelected(int id,bool select)
465 _lstViewPoints[id]->SetPosibleSelected(select);
467 // ----------------------------------------------------------------------------
468 void manualViewBaseContour::SetPointSelected(int id,bool select)
470 _lstViewPoints[id]->SetSelected(select);
472 // ----------------------------------------------------------------------------
473 void manualViewBaseContour::SelectAllPossibleSelected(bool select)
475 int i,size=_lstViewPoints.size();
476 for (i=0;i<size;i++){
477 SetPointPosibleSelected(i,select);
480 // ----------------------------------------------------------------------------
481 int manualViewBaseContour::SelectPosiblePoint(int x, int y, int z) // virtual
483 SelectAllPossibleSelected(false);
485 int id = GetIdPoint(x,y,z);
488 SetPointPosibleSelected(id,true);
492 // ----------------------------------------------------------------------------
493 bool manualViewBaseContour::SelectPosibleContour(int x, int y, int z)
496 SetPosibleSelected(result);
497 int id = GetIdPoint(x,y,z);
498 if( !GetEditable() && !_selected && id!= -1)
501 SetPosibleSelected(result);
505 if ( (GetEditable()==true) && (id==-1 ) && (this->_lstViewPoints.size()>=2) )
507 if (ifTouchContour(x,y,z)==true)
510 SetPosibleSelected(result);
514 if (GetEditable()==false)
516 if (ifTouchContour(x,y,z)==true)
519 SetPosibleSelected(result);
527 // ----------------------------------------------------------------------------
528 bool manualViewBaseContour::ifTouchContour(int x,int y, int z) // virtual
532 // ----------------------------------------------------------------------------
533 void manualViewBaseContour::UnSelectPoint(int i){
534 _lstViewPoints[i]->SetSelected(false);
537 // ----------------------------------------------------------------------------
538 void manualViewBaseContour::UnSelectLstPoints(){
541 // ----------------------------------------------------------------------------
542 void manualViewBaseContour::UnSelectAllPoints(){
543 int i,size=_lstViewPoints.size();
544 for (i=0;i<size;i++){
549 // ----------------------------------------------------------------------------
550 void manualViewBaseContour::SetModel(manualContourModel *manContModel){
551 _manContModel=manContModel;
553 // ----------------------------------------------------------------------------
554 void manualViewBaseContour::SetWxVtkBaseView(wxVtkBaseView *wxvtkbaseview){
555 _wxvtkbaseview = wxvtkbaseview;
557 // ----------------------------------------------------------------------------
558 void manualViewBaseContour::RefreshContour() // Virtual
561 // ----------------------------------------------------------------------------
562 double* manualViewBaseContour::GetVectorPointsXManualContour(){
564 int i,size = _sizePointsContour;
565 double *vx = (double*)malloc(sizeof(double)*size);
566 for (i=0;i<size;i++){
567 _pts->GetPoint(i,pp);
572 // ----------------------------------------------------------------------------
573 double* manualViewBaseContour::GetVectorPointsYManualContour()
576 int i,size = _sizePointsContour;
577 double *vy = (double*)malloc(sizeof(double)*size);
578 for (i=0;i<size;i++){
579 _pts->GetPoint(i,pp);
584 // ----------------------------------------------------------------------------
585 double* manualViewBaseContour::GetVectorPointsZManualContour()
588 int i,size = _sizePointsContour;
589 double *vz = (double*)malloc(sizeof(double)*size);
590 for (i=0;i<size;i++){
591 _pts->GetPoint(i,pp);
596 // ----------------------------------------------------------------------------
597 void manualViewBaseContour::Refresh() // virtual
599 if (_contourVtkActor!=NULL){
602 int i,size=_lstViewPoints.size();
603 for (i=0;i<size;i++){
605 _lstViewPoints[i]->UpdateColorActor();
609 if (_show_text==true)
614 vtkRenderWindowInteractor *vri = _wxvtkbaseview->GetWxVTKRenderWindowInteractor ();
617 _wxvtkbaseview->GetRenWin()->Render();
621 // ----------------------------------------------------------------------------
622 void manualViewBaseContour::RefreshText() // virtual
624 if( _textActor!=NULL)
625 _textActor -> SetInput("00");
627 // ----------------------------------------------------------------------------
628 void manualViewBaseContour::SetColorNormalContour(double r, double g, double b)
634 // ----------------------------------------------------------------------------
635 void manualViewBaseContour::GetColorNormalContour(double &r, double &g, double &b)
641 // ----------------------------------------------------------------------------
642 void manualViewBaseContour::SetColorEditContour(double r, double g, double b)
648 // ----------------------------------------------------------------------------
649 void manualViewBaseContour::GetColorEditContour(double &r, double &g, double &b)
655 // ----------------------------------------------------------------------------
656 void manualViewBaseContour::SetColorSelectContour(double r, double g, double b)
658 _coulorSelection_r = r;
659 _coulorSelection_g = g;
660 _coulorSelection_b = b;
662 // ----------------------------------------------------------------------------
663 void manualViewBaseContour::GetColorSelectContour(double &r, double &g, double &b)
665 r = _coulorSelection_r;
666 g = _coulorSelection_g;
667 b = _coulorSelection_b;
669 // ----------------------------------------------------------------------------
670 void manualViewBaseContour::UpdateColorActor()
672 if (_contourVtkActor!=NULL)
674 _contourVtkActor->GetProperty()->SetLineWidth( _widthline );
675 _contourVtkActor->GetProperty()->SetDiffuseColor( _coulorNormal_r , _coulorNormal_g , _coulorNormal_b );
676 if (_posibleSelected || (_posibleSelected && GetEditable() ) )
678 _contourVtkActor->GetProperty()->SetDiffuseColor( _coulorEdit_r , _coulorEdit_g , _coulorEdit_b );
682 _contourVtkActor->GetProperty()->SetDiffuseColor( _coulorSelection_r , _coulorSelection_g , _coulorSelection_b );
686 // ----------------------------------------------------------------------------
687 int manualViewBaseContour::GetIdPoint(int x, int y, int z) // virtual
690 if (_manContModel!=NULL){
694 TransfromeCoordViewWorld(xx,yy,zz);
695 ii=_manContModel->GetIdPoint(xx,yy,zz,_range,-1);
700 // ----------------------------------------------------------------------------
703 int manualViewBaseContour::GetNumberOfPoints()
705 return _lstViewPoints.size();
708 // ----------------------------------------------------------------------------
710 //JSTG 25-02-08 ---------------------------------------------------------------
711 /*int manualViewBaseContour::GetNumberOfPointsSpline()
713 return _sizePointsContour;
715 //----------------------------------------------------------------------------
717 //JSTG 25-02-08 ---------------------------------------------------------------
718 /*void manualViewBaseContour::SetNumberOfPointsSpline(int size)
720 _sizePointsContour = size;
722 //----------------------------------------------------------------------------
724 void manualViewBaseContour::TransfromeCoordViewWorld(double &X, double &Y, double &Z, int type) // Virtual
726 _wxvtkbaseview->TransfromeCoordScreenToWorld(X, Y, Z, type);
731 // wxVtk2DBaseView *wxvtk2Dbaseview = (wxVtk2DBaseView*)_wxvtkbaseview;
732 // wxvtk2Dbaseview->TransformCoordinate_spacing_ModelToView(X,Y,Z);
735 // ----------------------------------------------------------------------------
736 void manualViewBaseContour::SetRange(int range)
740 // ----------------------------------------------------------------------------
741 int manualViewBaseContour::GetRange()
745 // ----------------------------------------------------------------------------
746 void manualViewBaseContour::SetZ(int z)
750 // ----------------------------------------------------------------------------
751 int manualViewBaseContour::GetZ()
756 // ----------------------------------------------------------------------------
757 void manualViewBaseContour::InitMove(int x, int y, int z) // virtual
761 // ----------------------------------------------------------------------------
762 void manualViewBaseContour::MoveContour(int x, int y, int z) // virtual
765 // ----------------------------------------------------------------------------
766 void manualViewBaseContour::MoveContour(int horizontalUnits, int verticalUnits )// virtual
770 // ----------------------------------------------------------------------------
771 void manualViewBaseContour::GetMinMax( double &minX,double &minY, double &minZ, double &maxX, double &maxY, double &maxZ )// virtual
776 int size=_manContModel->GetSizeLstPoints();
781 bool ifFindZ = minZ!=-1.0 && maxZ!=-1.0;
787 for( i = 0; i < size; i++ )
789 mp=_manContModel->GetManualPoint(i);
841 // ----------------------------------------------------------------------------
842 void manualViewBaseContour::ClearContour()
844 if (_contourVtkActor!=NULL){
845 _wxvtkbaseview->GetRenderer()->RemoveActor( _contourVtkActor );
848 int i,size=_lstViewPoints.size();
849 for (i=0;i<size;i++){
854 // ----------------------------------------------------------------------------
855 void manualViewBaseContour::ClearPoint(int id)
859 // ----------------------------------------------------------------------------
860 void manualViewBaseContour::SetVisible(bool ok)
870 int i,size=_lstViewPoints.size();
871 for (i=0;i<size;i++){
872 actor = _lstViewPoints[i]->GetVtkActor();
873 actor->GetProperty()->SetOpacity( opacity );
875 _contourVtkActor->GetProperty()->SetOpacity( opacity );
876 _textActor->GetProperty()->SetOpacity( opacity );
877 _textActor->SetInput("00");
880 // ----------------------------------------------------------------------------
881 void manualViewBaseContour::SetShowText(bool ok)
884 if (_show_text==false)
886 _textActor->SetInput("00");
889 // ----------------------------------------------------------------------------
890 wxVtkBaseView *manualViewBaseContour::GetWxVtkBaseView()
892 return this->_wxvtkbaseview;
894 // ----------------------------------------------------------------------------
895 void manualViewBaseContour::GetSpacing(double spc[3])
901 // ----------------------------------------------------------------------------
902 void manualViewBaseContour::SetSpacing(double spc[3])