// Widget interface
textCtrl = new wxTextCtrl(panel, -1);
wxButton *btnAddPoint = new wxButton( panel, -1, _T("Add Point"));
+ wxButton *btnRenamePoint = new wxButton( panel, -1, _T("Rename point"));
wxButton *btnEraseLastPoint = new wxButton( panel, -1, _T("Erase Last point"));
wxButton *btnErasePoint = new wxButton( panel, -1, _T("Erase point"));
wxButton *btnDeleteAllPoints = new wxButton( panel, -1, _T("Delete all points"));
-
+ wxButton *btnSavePoints = new wxButton( panel, -1, _T("Save points"));
+ wxButton *btnLoadPoints = new wxButton( panel, -1, _T("Load points"));
+ txtNrPoints = new wxStaticText(panel,-1, _T("Number of points: 0"));
wxFlexGridSizer *sizer1 = new wxFlexGridSizer(1);
// sizer1->Add(new wxStaticText(panel,-1,_T(" ")));
- Connect(btnAddPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnAddPoint);
- Connect(btnEraseLastPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnEraseLastPoint);
- Connect(btnErasePoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnErasePoint);
- Connect(btnDeleteAllPoints->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnDeleteAllPoints);
-
- sizer1->Add(textCtrl);
- sizer1->Add(btnAddPoint);
- sizer1->Add(btnErasePoint);
- sizer1->Add(btnEraseLastPoint);
- sizer1->Add(btnDeleteAllPoints);
-
- sizer = sizer1;
- panel -> SetSizer(sizer);
- panel -> SetAutoLayout(true);
- panel -> Layout();
+ Connect(btnAddPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnAddPoint);
+ Connect(btnRenamePoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnRenamePoint);
+ Connect(btnEraseLastPoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnEraseLastPoint);
+ Connect(btnErasePoint->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnErasePoint);
+ Connect(btnDeleteAllPoints->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnDeleteAllPoints);
+ Connect(btnSavePoints->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnSavePoints);
+ Connect(btnLoadPoints->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WidgetShowNPoints::OnLoadPoints);
+
+ sizer1->Add(textCtrl);
+ sizer1->Add(btnAddPoint);
+ sizer1->Add(btnRenamePoint);
+ sizer1->Add(btnErasePoint);
+ sizer1->Add(btnEraseLastPoint);
+ sizer1->Add(btnDeleteAllPoints);
+ sizer1->Add(txtNrPoints);
+ sizer1->Add(btnSavePoints);
+ sizer1->Add(btnLoadPoints);
+
+ sizer = sizer1;
+ panel -> SetSizer(sizer);
+ panel -> SetAutoLayout(true);
+ panel -> Layout();
}
}
-
+std::string WidgetShowNPoints::CleanSpaces(std::string ss)
+{
+ int i;
+ while( (i=ss.find(32))>=0 )
+ {
+ ss.replace(i,1,"_");
+ }
+ return ss;
+}
+
+
//------------------------------------------------------------------------
void WidgetShowNPoints::OnAddPoint (wxCommandEvent& event)
{
lstPointsX.push_back( mpoint[0] );
lstPointsY.push_back( mpoint[1] );
lstPointsZ.push_back( mpoint[2] );
- lstLabels.push_back( (const char*) ( textCtrl->GetValue().mb_str() ) );
+
+ std::string strLabel = CleanSpaces( (const char*) ( textCtrl->GetValue().mb_str() ) );
+
+ lstLabels.push_back( strLabel );
// Sphere
vtkSphereSource *vtksphere = vtkSphereSource::New();
// Actor
vtkTextActor3D *textActor = vtkTextActor3D::New();
textActor->SetPosition( mradio+spc[0]*mpoint[0] , spc[1]*mpoint[1] , spc[2]*mpoint[2] );
- textActor->SetInput( (const char*) ( textCtrl->GetValue().mb_str() ) );
+ textActor->SetInput( strLabel.c_str() );
renderer->AddActor( textActor );
lstActorsText.push_back(textActor);
-
- renderer->GetRenderWindow()->Render();
SetOutputBox();
} // renderer
}
+
+ //------------------------------------------------------------------------
void WidgetShowNPoints::SetOutputBox()
{
+ renderer->GetRenderWindow()->Render();
+ wxString strTmp;
+ strTmp.Printf("Number of points: %d", (int)(lstPointsX.size()) );
+ txtNrPoints->SetLabel( strTmp );
+
//--BBTK
- mbbShowNPoints->bbSetOutputlstPointsX( GetLstPointsX() );
- mbbShowNPoints->bbSetOutputlstPointsY( GetLstPointsY() );
- mbbShowNPoints->bbSetOutputlstPointsZ( GetLstPointsZ() );
- mbbShowNPoints->bbSetOutputlstLabels( GetLstLabels() );
+ mbbShowNPoints->bbSetOutputlstPointsX( lstPointsX );
+ mbbShowNPoints->bbSetOutputlstPointsY( lstPointsY );
+ mbbShowNPoints->bbSetOutputlstPointsZ( lstPointsZ );
+ mbbShowNPoints->bbSetOutputlstLabels( lstLabels );
mbbShowNPoints->bbSignalOutputModification(std::string("lstPointsX"));
mbbShowNPoints->bbSignalOutputModification(std::string("lstPointsY"));
mbbShowNPoints->bbSignalOutputModification(std::string("lstPointsZ"));
mbbShowNPoints->bbSignalOutputModification(std::string("lstLabels"));
}
+ //------------------------------------------------------------------------
+ void WidgetShowNPoints::OnSavePoints(wxCommandEvent& event)
+ {
+ FILE *ff;
+ wxString filename="/Users/davila/Desktop/PDL_2/bbs/test.xls";
+ ff = fopen( (const char*) ( filename.mb_str() ) , "w+" );
+ if (ff!=NULL)
+ {
+ int i , size = (int) (lstActorsSphere.size());
+ fprintf(ff,"NumberOfPoints %d \n",size);
+ fprintf(ff," X\tY\tZ\tvalue\tLabel\n");
+ int x, y, z;
+ double value;
+ for (i=0; i<size; i++)
+ {
+ x=lstPointsX[i];
+ y=lstPointsY[i];
+ z=lstPointsZ[i];
+ value= mimage->GetScalarComponentAsDouble(x,y,z,0);
+ fprintf(ff,"%d\t %d\t %d\t %f\t %s\n", x , y , z , value , lstLabels[i].c_str());
+ } // for
+ fclose(ff);
+ } else { // else ff
+ printf("WidgetShowNPoints::OnSavePoints ...Error... creating file");
+ } //ff
+
+ }
+
+ //------------------------------------------------------------------------
+ void WidgetShowNPoints::OnLoadPoints(wxCommandEvent& event)
+ {
+ }
+
+ int WidgetShowNPoints::GetNearestPoint()
+ {
+ int id=-1;
+ int i, size=(int)(lstActorsSphere.size());
+ double spc[3];
+ mimage->GetSpacing(spc);
+
+ for ( i=0 ; i<size; i++ )
+ {
+ double rx = spc[0]*(mpoint[0] - lstPointsX [i]);
+ double ry = spc[1]*(mpoint[1] - lstPointsY [i]);
+ double rz = spc[2]*(mpoint[2] - lstPointsZ [i]);
+ if ( rx*rx + ry*ry + rz*rz <= mradio*mradio)
+ {
+ id=i;
+ } // if
+ } // for
+
+ return id;
+ }
+
+ //------------------------------------------------------------------------
+ void WidgetShowNPoints::OnRenamePoint(wxCommandEvent& event)
+ {
+ int id=GetNearestPoint();
+ if (id>=0)
+ {
+ std::string strLabel = CleanSpaces( (const char*) ( textCtrl->GetValue().mb_str() ) );
+ lstLabels[id] = CleanSpaces( (const char*) (textCtrl->GetValue().mb_str()) ) ;
+ lstActorsText[id]->SetInput( lstLabels[id].c_str() );
+ SetOutputBox();
+ }
+ }
+
//------------------------------------------------------------------------
void WidgetShowNPoints::ErasePoint(int id)
{
lstPointsZ.erase( lstPointsZ.begin()+id );
lstLabels.erase( lstLabels.begin()+id );
- renderer->GetRenderWindow()->Render();
SetOutputBox();
} // if id
//------------------------------------------------------------------------
void WidgetShowNPoints::OnErasePoint(wxCommandEvent& event)
{
- int id=-1;
- int i, size=(int)(lstActorsSphere.size());
- double spc[3];
- mimage->GetSpacing(spc);
-
- for ( i=0 ; i<size; i++ )
- {
- double rx = spc[0]*(mpoint[0] - lstPointsX [i]);
- double ry = spc[1]*(mpoint[1] - lstPointsY [i]);
- double rz = spc[2]*(mpoint[2] - lstPointsZ [i]);
- if ( rx*rx + ry*ry + rz*rz <= mradio*mradio)
- {
- id=i;
- } // if
- } // for
- ErasePoint(id);
+ ErasePoint( GetNearestPoint() );
}
//------------------------------------------------------------------------